﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OPMS_V1.BOL;
using System.Text;

namespace OPMS_V1.Public
{
    public partial class StartAd : System.Web.UI.Page
    {
        //Instantiatiting the Business Object
        Advertisement advertise = new Advertisement();

        /// <summary>
        /// This function is used for the page load event.
        /// It generates the random taskID, and matches to the database for its Existence.
        /// It only assigns if there is a unique task ID
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            string mode = null;
            //Getting the Mode from the Application["..."] variable
            mode = System.Convert.ToString(Session["propertyAdType"]);

            string randomstring;

            do
            {
                //Generating the Random Task ID which is not present in Database
                randomstring = advertise.RandomString();
            }while(advertise.checkTaskId(randomstring));

            //Assign the taskID and Modes to the Session["..."] variable
            Session["TaskID"] = randomstring;
            Session["propertyAdType"] = mode;

            //Redirecting the page to the Build Ad with the TaskID and Modes
            Response.Redirect("~\\Public\\Build.aspx?taskid="+randomstring+"&Mode="+mode);
        }

        
    }
}
